/****************************************************************************
 *  QLyrics - A simple lyrics viewer.                                       *
 *  Copyright (C) 2008  hsys <hanshuiys@gmail.com>                          *
 *                                                                          *
 *  This program is free software; you can redistribute it and/or modify    *
 *  it under the terms of the GNU General Public License as published by    *
 *  the Free Software Foundation; either version 3 of the License, or       *
 *  (at your option) any later version.                                     *
 *                                                                          *
 *  This program is distributed in the hope that it will be useful,         *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU General Public License for more details.                            *
 *                                                                          *
 *  You should have received a copy of the GNU General Public License       *
 *  along with this program; if not, write to the Free Software Foundation, *
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA       *
 ****************************************************************************/

#include "lyricspanelmanager.h"
#include "lyricsnormalpanel.h"
#include "lyricsverticalpanel.h"
#include "lyricshorizontalpanel.h"

LyricsPanelManager* LyricsPanelManager::sm_inst = NULL;

void LyricsPanelManager::buildInstance(QObject* parent) {
    if (sm_inst == NULL)
        sm_inst = new LyricsPanelManager(parent);
};

LyricsPanelManager* LyricsPanelManager::getInstance() {
    return sm_inst;
};

LyricsPanelManager::LyricsPanelManager(QObject* parent) : QObject(parent) {
    m_panelPrototype.push_back(new LyricsNormalPanel::Builder());
    m_panelPrototype.push_back(new LyricsVerticalPanel::Builder());
    m_panelPrototype.push_back(new LyricsHorizontalPanel::Builder());
};

LyricsPanelManager::~LyricsPanelManager() {
    std::vector<LyricsPanel::Builder*>::const_iterator px;
    // delete all panel
    for (px = m_panelPrototype.begin(); px != m_panelPrototype.end(); ++px) {
        delete *px;
    };
};

const LyricsPanel::Builder* LyricsPanelManager::findPanel(const QString& name) const {
    std::vector<LyricsPanel::Builder*>::const_iterator px;
    // find the specified panel
    for (px = m_panelPrototype.begin(); px != m_panelPrototype.end(); ++px) {
        if ((*px)->getPanelName() == name)
            return *px;
    };
    // if not found, return the first one
    return *(m_panelPrototype.begin());
};
